

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Index &mdash; pymilvus 1.0.1 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script type="text/javascript" src="_static/jquery.js"></script>
        <script type="text/javascript" src="_static/underscore.js"></script>
        <script type="text/javascript" src="_static/doctools.js"></script>
        <script type="text/javascript" src="_static/language_data.js"></script>
        <script type="text/javascript" src="_static/clipboard.min.js"></script>
        <script type="text/javascript" src="_static/copybutton.js"></script>
        <script async="async" type="text/javascript" src="https://assets.readthedocs.org/static/javascript/readthedocs-doc-embed.js"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/copybutton.css" type="text/css" />
    <link rel="author" title="About these documents" href="about.html" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Search results" href="results.html" />
    <link rel="prev" title="API reference" href="api.html" /> 

<!-- RTD Extra Head -->

<link rel="stylesheet" href="https://assets.readthedocs.org/static/css/readthedocs-doc-embed.css" type="text/css" />

<script type="application/json" id="READTHEDOCS_DATA">{"ad_free": false, "api_host": "https://readthedocs.org", "build_date": "2021-03-26T03:06:15Z", "builder": "sphinx", "canonical_url": null, "commit": "26c94265", "docroot": "/docs/source/", "features": {"docsearch_disabled": false}, "global_analytics_code": "UA-17997319-1", "language": "en", "page": "param", "programming_language": "py", "project": "pymilvus", "proxied_api_host": "/_", "source_suffix": ".rst", "subprojects": {}, "theme": "sphinx_rtd_theme", "user_analytics_code": "", "version": "1.0"}</script>

<!--
Using this variable directly instead of using `JSON.parse` is deprecated.
The READTHEDOCS_DATA global variable will be removed in the future.
-->
<script type="text/javascript">
READTHEDOCS_DATA = JSON.parse(document.getElementById('READTHEDOCS_DATA').innerHTML);
</script>

<script type="text/javascript" src="https://assets.readthedocs.org/static/javascript/readthedocs-analytics.js" async="async"></script>

<!-- end RTD <extrahead> -->
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html" class="icon icon-home"> pymilvus
          

          
          </a>

          
            
            
            
              <div class="version">
                1.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Table of Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="api.html">API reference</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Index</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#vector-index">Vector Index</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#flat">FLAT</a></li>
<li class="toctree-l3"><a class="reference internal" href="#ivf-flat">IVF_FLAT</a></li>
<li class="toctree-l3"><a class="reference internal" href="#ivf-pq">IVF_PQ</a></li>
<li class="toctree-l3"><a class="reference internal" href="#ivf-sq8">IVF_SQ8</a></li>
<li class="toctree-l3"><a class="reference internal" href="#ivf-sq8-h">IVF_SQ8_H</a></li>
<li class="toctree-l3"><a class="reference internal" href="#annoy">ANNOY</a></li>
<li class="toctree-l3"><a class="reference internal" href="#hnsw">HNSW</a></li>
<li class="toctree-l3"><a class="reference internal" href="#rnsg">RNSG</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="results.html">Search results</a></li>
<li class="toctree-l1"><a class="reference internal" href="changes.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="contribute.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="about.html">About this documentation</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">pymilvus</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>Index</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            
              <a href="https://github.com/milvus-io/pymilvus/blob/1.0/docs/source/param.rst" class="fa fa-github"> Edit on GitHub</a>
            
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">

           <div itemprop="articleBody">
            
  <div class="section" id="index">
<h1>Index<a class="headerlink" href="#index" title="Permalink to this headline">¶</a></h1>
<p><a class="reference external" href="https://github.com/milvus-io">Milvus</a> support to create index to accelerate vector approximate search.</p>
<p>To learn how to create an index by python client, see method <a class="reference external" href="api.html#milvus.Milvus.create_index">create_index()</a> and
<a class="reference external" href="https://github.com/milvus-io/pymilvus/tree/1.0/examples">index example</a> .</p>
<p>For more detailed information about indexes, please refer to <a class="reference external" href="https://milvus.io/docs/index.md">Milvus documentation index chapter.</a></p>
<p>To learn how to choose an appropriate index for your application scenarios, please read <a class="reference external" href="https://medium.com/&#64;milvusio/how-to-choose-an-index-in-milvus-4f3d15259212">How to Select an Index in Milvus</a>.</p>
<p>To learn how to choose an appropriate index for a metric, see <a class="reference external" href="https://www.milvus.io/docs/metric.md">Distance Metrics</a>.</p>
<div class="section" id="vector-index">
<h2>Vector Index<a class="headerlink" href="#vector-index" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p><a class="reference internal" href="#flat">FLAT</a></p></li>
<li><p><a class="reference internal" href="#ivf-flat">IVF_FLAT</a></p></li>
<li><p><a class="reference internal" href="#ivf-sq8">IVF_SQ8</a></p></li>
<li><p><a class="reference internal" href="#ivf-sq8-h">IVF_SQ8_H</a></p></li>
<li><p><a class="reference internal" href="#ivf-pq">IVF_PQ</a></p></li>
<li><p><a class="reference internal" href="#hnsw">HNSW</a></p></li>
<li><p><a class="reference internal" href="#annoy">ANNOY</a></p></li>
<li><p><a class="reference internal" href="#rnsg">RNSG</a></p></li>
</ul>
<div class="section" id="flat">
<h3>FLAT<a class="headerlink" href="#flat" title="Permalink to this headline">¶</a></h3>
<p>If FLAT index is used, the vectors are stored in an array of float/binary data without any compression. during
searching vectors, all indexed vectors are decoded sequentially and compared to the query vectors.</p>
<p>FLAT index provides 100% query recall rate. Compared to other indexes, it is the most efficient indexing method
when the number of queries is small.</p>
<p>The inserted and index-inbuilt vectors and index-dropped vectors are regard as built with <code class="docutils literal notranslate"><span class="pre">FLAT</span></code>.</p>
<ul class="simple">
<li><p>building parameters:
<strong>N/A</strong></p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># FLAT</span>
<span class="n">client</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span> <span class="n">IndexType</span><span class="o">.</span><span class="n">FLAT</span><span class="p">)</span>
</pre></div>
</div>
<ul class="simple">
<li><p>search parameters:
<strong>N/A</strong></p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># FLAT</span>
<span class="n">client</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
              <span class="mi">1</span><span class="p">,</span>
              <span class="n">query_vectors</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="ivf-flat">
<h3>IVF_FLAT<a class="headerlink" href="#ivf-flat" title="Permalink to this headline">¶</a></h3>
<p><strong>IVF</strong> (<em>Inverted File</em>) is an index type based on quantization. It divides the points in space into <code class="docutils literal notranslate"><span class="pre">nlist</span></code>
units by clustering method. During searching vectors, it compares the distances between the target vector
and the center of all the units, and then select the <code class="docutils literal notranslate"><span class="pre">nprobe</span></code> nearest unit. Then, it compares all the vectors
in these selected cells to get the final result.</p>
<p>IVF_FLAT is the most basic IVF index, and the encoded data stored in each unit is consistent with the original data.</p>
<ul>
<li><p>building parameters:</p>
<p><strong>nlist</strong>: Number of cluster units.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># IVF_FLAT</span>
<span class="n">client</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span> <span class="n">IndexType</span><span class="o">.</span><span class="n">IVF_FLAT</span><span class="p">,</span> <span class="p">{</span>
    <span class="s2">&quot;nlist&quot;</span><span class="p">:</span> <span class="mi">100</span>      <span class="c1"># int. 1~65536</span>
<span class="p">})</span>
</pre></div>
</div>
<ul>
<li><p>search parameters:</p>
<p><strong>nprobe</strong>: Number of inverted file cell to probe.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># IVF_FLAT</span>
<span class="n">client</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
              <span class="mi">1</span><span class="p">,</span>
              <span class="n">query_vectors</span><span class="p">,</span>
              <span class="n">params</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">&quot;nprobe&quot;</span><span class="p">:</span> <span class="mi">8</span> <span class="c1"># int. 1~nlist(cpu), 1~min[2048, nlist](gpu)</span>
              <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="ivf-pq">
<h3>IVF_PQ<a class="headerlink" href="#ivf-pq" title="Permalink to this headline">¶</a></h3>
<p><strong>PQ</strong> (<em>Product Quantization</em>) uniformly decomposes the original high-dimensional vector space into
Cartesian products of <code class="docutils literal notranslate"><span class="pre">m</span></code> low-dimensional vector spaces, and then quantizes the decomposed low-dimensional
vector spaces. In the end, each vector is stored in <code class="docutils literal notranslate"><span class="pre">m</span></code> × <code class="docutils literal notranslate"><span class="pre">nbits</span></code> bits. Instead of calculating the distances
between the target vector and the center of all the units, product quantization enables the calculation of
distances between the target vector, and the clustering center of each low-dimensional space and greatly reduces
the time complexity and space complexity of the algorithm.</p>
<p>IVF_PQ performs IVF index clustering, and then quantizes the product of vectors. Its index file is even
smaller than IVF_SQ8, but it also causes a loss of accuracy during searching.</p>
<ul>
<li><p>building parameters:</p>
<p><strong>nlist</strong>: Number of cluster units.</p>
<p><strong>m</strong>: Number of factors of product quantization. <strong>CPU-only</strong> Milvus: <code class="docutils literal notranslate"><span class="pre">m</span> <span class="pre">≡</span> <span class="pre">dim</span> <span class="pre">(mod</span> <span class="pre">m)</span></code>; <strong>GPU-enabled</strong> Milvus: <code class="docutils literal notranslate"><span class="pre">m</span></code> ∈ {1, 2, 3, 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 56, 64, 96}, and (dim / m) ∈ {1, 2, 3, 4, 6, 8, 10, 12, 16, 20, 24, 28, 32}. (<code class="docutils literal notranslate"><span class="pre">m</span></code> x 1024) ≥ <code class="docutils literal notranslate"><span class="pre">MaxSharedMemPerBlock</span></code> of your graphics card.</p>
<p><strong>nbits</strong>: Number of bits in which each low-dimensional vector is stored.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># IVF_PQ</span>
<span class="n">client</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
                    <span class="n">IndexType</span><span class="o">.</span><span class="n">IVF_PQ</span><span class="p">,</span>
                    <span class="p">{</span>
                      <span class="s2">&quot;nlist&quot;</span><span class="p">:</span> <span class="mi">100</span><span class="p">,</span>     <span class="c1"># int. 1~65536</span>
                      <span class="s2">&quot;m&quot;</span><span class="p">:</span> <span class="mi">8</span>            <span class="c1"># int. 1~16. 8 by default</span>
                    <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
<ul>
<li><p>search parameters:</p>
<p><strong>nprobe</strong>: Number of inverted file cell to probe.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># IVF_PQ</span>
<span class="n">client</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
              <span class="mi">1</span><span class="p">,</span>
              <span class="n">query_vectors</span><span class="p">,</span>
              <span class="n">params</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">&quot;nprobe&quot;</span><span class="p">:</span> <span class="mi">8</span> <span class="c1"># int. 1~nlist(cpu), 1~min[2048, nlist](gpu)</span>
              <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="ivf-sq8">
<h3>IVF_SQ8<a class="headerlink" href="#ivf-sq8" title="Permalink to this headline">¶</a></h3>
<p><strong>IVF_SQ8</strong> does scalar quantization for each vector placed in the unit based on IVF. Scalar quantization
converts each dimension of the original vector from a 4-byte floating-point number to a 1-byte unsigned integer,
so the IVF_SQ8 index file occupies much less space than the IVF_FLAT index file.
However, scalar quantization results in a loss of accuracy during searching vectors.</p>
<ul>
<li><p>building parameters:</p>
<p><strong>nlist</strong>: Number of cluster units.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># IVF_SQ8</span>
<span class="n">client</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
                    <span class="n">IndexType</span><span class="o">.</span><span class="n">IVF_SQ8</span><span class="p">,</span>
                    <span class="p">{</span>
                      <span class="s2">&quot;nlist&quot;</span><span class="p">:</span> <span class="mi">100</span>      <span class="c1"># int. 1~65536</span>
                    <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
<ul>
<li><p>search parameters:</p>
<p><strong>nprobe</strong>: Number of inverted file cell to probe.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># IVF_SQ8</span>
<span class="n">client</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
              <span class="mi">1</span><span class="p">,</span>
              <span class="n">query_vectors</span><span class="p">,</span>
              <span class="n">params</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">&quot;nprobe&quot;</span><span class="p">:</span> <span class="mi">8</span>       <span class="c1"># int. 1~nlist(cpu), 1~min[2048, nlist](gpu)</span>
              <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="ivf-sq8-h">
<h3>IVF_SQ8_H<a class="headerlink" href="#ivf-sq8-h" title="Permalink to this headline">¶</a></h3>
<p>Optimized version of IVF_SQ8 that requires both CPU and GPU to work. Unlike IVF_SQ8, IVF_SQ8_H uses a GPU-based
coarse quantizer, which greatly reduces time to quantize.</p>
<p>IVF_SQ8H is an IVF_SQ8 index that optimizes query execution.</p>
<p>The query method is as follows:</p>
<ul>
<li><p>If <code class="docutils literal notranslate"><span class="pre">nq</span></code> ≥ <code class="docutils literal notranslate"><span class="pre">gpu_search_threshold</span></code>, GPU handles the entire query task.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">nq</span></code> &lt; <code class="docutils literal notranslate"><span class="pre">gpu_search_threshold</span></code>, GPU handles the task of retrieving the <code class="docutils literal notranslate"><span class="pre">nprobe</span></code> nearest unit in the IVF
index file, and CPU handles the rest.</p></li>
<li><p>building parameters:</p>
<p><strong>nlist</strong>: Number of cluster units.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># IVF_SQ8_H</span>
<span class="n">client</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
                    <span class="n">IndexType</span><span class="o">.</span><span class="n">IVF_SQ8_H</span><span class="p">,</span>
                    <span class="p">{</span>
                      <span class="s2">&quot;nlist&quot;</span><span class="p">:</span> <span class="mi">100</span>      <span class="c1"># int. 1~65536</span>
                    <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
<ul>
<li><p>search parameters:</p>
<p><strong>nprobe</strong>: Number of inverted file cell to probe.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># IVF_SQ8_H</span>
<span class="n">client</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
              <span class="mi">1</span><span class="p">,</span>
              <span class="n">query_vectors</span><span class="p">,</span>
              <span class="n">params</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">&quot;nprobe&quot;</span><span class="p">:</span> <span class="mi">8</span>       <span class="c1"># int. 1~nlist(cpu), 1~min[2048, nlist](gpu)</span>
              <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="annoy">
<h3>ANNOY<a class="headerlink" href="#annoy" title="Permalink to this headline">¶</a></h3>
<p><strong>ANNOY</strong> (<em>Approximate Nearest Neighbors Oh Yeah</em>) is an index that uses a hyperplane to divide a
high-dimensional space into multiple subspaces, and then stores them in a tree structure.</p>
<p>When searching for vectors, ANNOY follows the tree structure to find subspaces closer to the target vector,
and then compares all the vectors in these subspaces (The number of vectors being compared should not be
less than <code class="docutils literal notranslate"><span class="pre">search_k</span></code>) to obtain the final result. Obviously, when the target vector is close to the edge of
a certain subspace, sometimes it is necessary to greatly increase the number of searched subspaces to obtain
a high recall rate. Therefore, ANNOY uses <code class="docutils literal notranslate"><span class="pre">n_trees</span></code> different methods to divide the whole space, and searches
all the dividing methods simultaneously to reduce the probability that the target vector is always at the edge of the subspace.</p>
<ul>
<li><p>building parameters:</p>
<p><strong>n_trees</strong>:  The number of methods of space division.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># ANNOY</span>
<span class="n">client</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
                    <span class="n">IndexType</span><span class="o">.</span><span class="n">ANNOY</span><span class="p">,</span>
                    <span class="p">{</span>
                      <span class="s2">&quot;n_trees&quot;</span><span class="p">:</span> <span class="mi">8</span>      <span class="c1"># int. 1~1024</span>
                    <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
<ul>
<li><p>search parameters:</p>
<p><strong>search_k</strong>: The number of nodes to search. -1 means 5% of the whole data.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># ANNOY</span>
<span class="n">client</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
              <span class="mi">1</span><span class="p">,</span>
              <span class="n">query_vectors</span><span class="p">,</span>
              <span class="n">params</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">&quot;search_k&quot;</span><span class="p">:</span> <span class="o">-</span><span class="mi">1</span>    <span class="c1"># int. {-1} U [top_k, n*n_trees], n represents vectors count.</span>
              <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="hnsw">
<h3>HNSW<a class="headerlink" href="#hnsw" title="Permalink to this headline">¶</a></h3>
<p><strong>HNSW</strong> (<em>Hierarchical Navigable Small World Graph</em>) is a graph-based indexing algorithm. It builds a
multi-layer navigation structure for an image according to certain rules. In this structure, the upper
layers are more sparse and the distances between nodes are farther; the lower layers are denser and
he distances between nodes are closer. The search starts from the uppermost layer, finds the node closest
to the target in this layer, and then enters the next layer to begin another search. After multiple iterations,
it can quickly approach the target position.</p>
<p>In order to improve performance, HNSW limits the maximum degree of nodes on each layer of the graph to <code class="docutils literal notranslate"><span class="pre">M</span></code>.
In addition, you can use <code class="docutils literal notranslate"><span class="pre">efConstruction</span></code> (when building index) or <code class="docutils literal notranslate"><span class="pre">ef</span></code> (when searching targets) to specify a search range.</p>
<ul>
<li><p>building parameters:</p>
<p><strong>M</strong>: Maximum degree of the node.</p>
<p><strong>efConstruction</strong>: Take the effect in stage of index construction.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># HNSW</span>
<span class="n">client</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
                    <span class="n">IndexType</span><span class="o">.</span><span class="n">HNSW</span><span class="p">,</span>
                    <span class="p">{</span>
                      <span class="s2">&quot;M&quot;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span>              <span class="c1"># int. 4~64</span>
                      <span class="s2">&quot;efConstruction&quot;</span><span class="p">:</span> <span class="mi">40</span>  <span class="c1"># int. 8~512</span>
                    <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
<ul>
<li><p>search parameters:</p>
<p><strong>ef</strong>: Take the effect in stage of search scope, should be larger than <code class="docutils literal notranslate"><span class="pre">top_k</span></code>.</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># HNSW</span>
<span class="n">client</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
              <span class="mi">1</span><span class="p">,</span>
              <span class="n">query_vectors</span><span class="p">,</span>
              <span class="n">params</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">&quot;ef&quot;</span><span class="p">:</span> <span class="mi">64</span>          <span class="c1"># int. top_k~32768</span>
              <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="rnsg">
<h3>RNSG<a class="headerlink" href="#rnsg" title="Permalink to this headline">¶</a></h3>
<p><strong>RNSG</strong> (<em>Refined Navigating Spreading-out Graph</em>) is a graph-based indexing algorithm. It sets the center
position of the whole image as a navigation point, and then uses a specific edge selection strategy to control
the out-degree of each point (less than or equal to <code class="docutils literal notranslate"><span class="pre">out_degree</span></code>). Therefore, it can reduce memory usage and
quickly locate the target position nearby during searching vectors.</p>
<p>The graph construction process of NSG is as follows:</p>
<ol class="arabic simple">
<li><p>Find <code class="docutils literal notranslate"><span class="pre">knng</span></code> nearest neighbors for each point.</p></li>
<li><p>Iterate at least <code class="docutils literal notranslate"><span class="pre">search_length</span></code> times based on <code class="docutils literal notranslate"><span class="pre">knng</span></code> nearest neighbor nodes to select <code class="docutils literal notranslate"><span class="pre">candidate_pool_size</span></code> possible nearest neighbor nodes.</p></li>
<li><p>Construct the out-edge of each point in the selected <code class="docutils literal notranslate"><span class="pre">candidate_pool_size</span></code> nodes according to the edge selection strategy.</p></li>
</ol>
<p>The query process is similar to the graph building process. It starts from the navigation point and iterates at least <code class="docutils literal notranslate"><span class="pre">search_length</span></code> times to get the final result.</p>
<ul>
<li><p>building parameters:</p>
<p><strong>search_length</strong>: Number of query iterations.</p>
<p><strong>out_degree</strong>: Maximum out-degree of the node.</p>
<p><strong>candidate_pool_size</strong>: Candidate pool size of the node.</p>
<p><strong>knng</strong>: Number of nearest neighbors</p>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># RNSG</span>
<span class="n">client</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
                    <span class="n">IndexType</span><span class="o">.</span><span class="n">RNSG</span><span class="p">,</span>
                    <span class="p">{</span>
                      <span class="s2">&quot;search_length&quot;</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span>         <span class="c1"># int. 10~300</span>
                      <span class="s2">&quot;out_degree&quot;</span><span class="p">:</span> <span class="mi">30</span><span class="p">,</span>            <span class="c1"># int. 5~300</span>
                      <span class="s2">&quot;candidate_pool_size&quot;</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>  <span class="c1"># int. 50~1000</span>
                      <span class="s2">&quot;knng&quot;</span><span class="p">:</span> <span class="mi">50</span>                   <span class="c1"># int. 5~300</span>
                    <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
<ul>
<li><p>search parameters:</p>
<blockquote>
<div><p><strong>search_length</strong>: Number of query iterations</p>
</div></blockquote>
</li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># RNSG</span>
<span class="n">client</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">collection_name</span><span class="p">,</span>
              <span class="mi">1</span><span class="p">,</span>
              <span class="n">query_vectors</span><span class="p">,</span>
              <span class="n">params</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">&quot;search_length&quot;</span><span class="p">:</span> <span class="mi">100</span>  <span class="c1"># int. 10~300</span>
              <span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
<p><em>Section author: <a class="reference external" href="https://github.com/godchen0212">Godchen&#64;milvus</a></em></p>
</div>
</div>
</div>


           </div>
           
          </div>
    <a href="https://github.com/milvus-io/pymilvus">
        <img style="position: absolute; top: 0; right: 0; border: 0;" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_green_007200.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1">
    </a>

          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="results.html" class="btn btn-neutral float-right" title="Search results" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="api.html" class="btn btn-neutral float-left" title="API reference" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019-2021 Zilliz. All rights reserved.
      
        <span class="commit">
          Revision <code>26c94265</code>.
        </span>
      

    </p>
  </div> 

</footer>

        </div>
      </div>

    </section>

  </div>
  

  <div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      <span class="fa fa-book"> Read the Docs</span>
      v: 1.0
      <span class="fa fa-caret-down"></span>
    </span>
    <div class="rst-other-versions">
      <dl>
        <dt>Versions</dt>
        
          <dd><a href="/en/latest/">latest</a></dd>
        
          <dd><a href="/en/stable/">stable</a></dd>
        
          <dd><a href="/en/1.0/">1.0</a></dd>
        
          <dd><a href="/en/0.4.0/">0.4.0</a></dd>
        
          <dd><a href="/en/0.3.0/">0.3.0</a></dd>
        
      </dl>
      <dl>
        <dt>Downloads</dt>
        
          <dd><a href="//pymilvus.readthedocs.io/_/downloads/en/1.0/pdf/">pdf</a></dd>
        
          <dd><a href="//pymilvus.readthedocs.io/_/downloads/en/1.0/htmlzip/">html</a></dd>
        
          <dd><a href="//pymilvus.readthedocs.io/_/downloads/en/1.0/epub/">epub</a></dd>
        
      </dl>
      <dl>
        <dt>On Read the Docs</dt>
          <dd>
            <a href="//readthedocs.org/projects/pymilvus/?fromdocs=pymilvus">Project Home</a>
          </dd>
          <dd>
            <a href="//readthedocs.org/builds/pymilvus/?fromdocs=pymilvus">Builds</a>
          </dd>
      </dl>
      <hr/>
      Free document hosting provided by <a href="http://www.readthedocs.org">Read the Docs</a>.

    </div>
  </div>



  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
   

</body>
</html>